package com.cloudkinto.service.consumer.mail;

import com.alibaba.fastjson.JSONObject;
import com.cloudkinto.common.RabbitQueueConstant;
import com.cloudkinto.entity.MailAccountDo;
import com.cloudkinto.service.consumer.vo.mail.MailOneConsumerReq;
import com.cloudkinto.service.consumer.vo.mail.MailOrderConsumerReq;
import com.cloudkinto.service.consumer.vo.mail.MailSyncConsumerReq;
import com.cloudkinto.service.consumer.vo.order.PlatOrderCancelConsumerReq;
import com.cloudkinto.service.consumer.vo.order.PlatOrderSendConsumerReq;
import com.cloudkinto.service.mail.MailAccountService;
import com.cloudkinto.service.mail.MailService;
import com.cloudkinto.service.platform.PlatformOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class MailConsumer {
    private final MailService mailService;


    /**
     * 根据账号同步邮件
     * @param msg
     */
    @RabbitListener(queuesToDeclare = @Queue(RabbitQueueConstant.MailAccount_Sync))
    public void syncMail(String msg) {
        MailSyncConsumerReq list = JSONObject.parseObject(msg, MailSyncConsumerReq.class);
        mailService.syncMail(list.getAccountId(), list.isAutoFlag());
    }

    /**
     * 同步一个邮件
     * @param msg
     */
//    @RabbitListener(queuesToDeclare = @Queue(RabbitQueueConstant.MailAccount_SyncOne_OneMessage))
//    public void syncOneMailMessage(String msg) {
//        MailOneConsumerReq list = JSONObject.parseObject(msg, MailOneConsumerReq.class);
//        try {
//            mailService.syncOneMailMsg(list.getMessage(), list.getFolderName(), list.getAccountId(), list.getMailNo(), list.getStoreId(), list.getCompanyId());
//        }catch (Exception e) {
//            e.printStackTrace();
//        }
//    }



    /**
     * 根据邮件内容解析成订单
     * @param msg
     */
    @RabbitListener(queuesToDeclare = @Queue(RabbitQueueConstant.PlatformStore_MailOrder_Qoo10_Sync))
    public void syncMailOrder(String msg) {
        MailOrderConsumerReq list = JSONObject.parseObject(msg, MailOrderConsumerReq.class);
        try {
            mailService.syncMailOrder(list);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }


}
